<%@ Page Language="C#"  MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<DecisionMaking.BusinessLogic.Model.CandidateModel>" %>
<%@ Import Namespace="DecisionMaking.Domain" %>
<%@ Import Namespace="DecisionMaking.WebApp" %>
<%@ Import Namespace="MvcContrib.UI.MenuBuilder" %>

<asp:Content ContentPlaceHolderID="TitleContent" runat="server"><%=Model.CandidateId == null ? "New" : "Edit"%> Candidate</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MenuContent" runat="server">
    <% Html.Menu(Navigation.MainMenu(Url, Model.EnvironmentId)); %>
</asp:Content>

<asp:Content ContentPlaceHolderID="MainContent" runat="server">
    <%= Html.ValidationSummary("Candidate creation was unsuccessful. Please correct the errors and try again.") %>

    <% using (Html.BeginForm()) { %>
        <div>
        	<%= Html.HiddenFor(m => m.CandidateId)%>
        	<%= Html.HiddenFor(m => m.EnvironmentId) %>
            <fieldset>
                <legend>Candidate Information</legend>
                <p class="field-multi-line field-textbox">
                    <%= Html.LabelFor(m => m.Name) %>
                    <%= Html.TextBoxFor(m => m.Name) %>
                    <%= Html.ValidationMessageFor(m => m.Name) %>
                </p>
                <p class="field-multi-line field-textbox">
                    <label for="IndependentVariableValue>"><%=((DecisionMaking.Domain.Environment)ViewData["environment"]).IndependentVariableName%></label>
                    <%= Html.TextBoxFor(m => m.IndependentVariableValue)%>
                    <%= Html.ValidationMessageFor(m => m.IndependentVariableValue)%>
                </p>                
            </fieldset>
            <fieldset>
            	<legend>Cue Values</legend>
                <% for(var i = 0; i < Model.CueValues.Count; i++) 
                {
                    // we have to copy the attribute into the closure, otherwise only the last value is used in all closure instances
                    var index = i;
                   
                    // the following block renders a paragraph for each cue attribute value, allowing ASP to automatically bind the inputs into the CueModel
                     %>
                    <p class="field-multi-line field-textbox">
                       <%= Html.HiddenFor(m => m.CueValues[index].CueId)%>
                       <label for="CueValues[<%= index %>]"><%= Model.CueValues[index].Name%></label>
                       <%= Html.TextBoxFor(m => m.CueValues[index].Value)%>
                       <%= Html.ValidationMessageFor(m => m.CueValues[index].Value)%>
                    </p>
                <% } %>
            </fieldset>
            <p>
                <input type="submit" value="<%=Model.CandidateId == null ? "Create" : "Save"%> " />
            </p>            
        </div>
    <% } %>
</asp:Content>